package com.ysu.demo.controller;


import ch.qos.logback.core.joran.util.beans.BeanUtil;
import com.ysu.demo.VO.ResultVO;
import com.ysu.demo.dataobject.College;
import com.ysu.demo.enums.ExceptionEnum;
import com.ysu.demo.exception.BaseException;
import com.ysu.demo.from.CollegeListFrom;
import com.ysu.demo.service.ICollegeService;
import com.ysu.demo.utlis.ResultUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lhw
 * @since 2019-08-21
 */
@RestController
@RequestMapping("/college")
public class CollegeController {
    @Autowired
    ICollegeService collegeService;

    @PostMapping("/list")
    public ResultVO getList(@RequestBody @Valid CollegeListFrom from,
                            BindingResult bindingResult){
        if(bindingResult.hasErrors()){
            throw new BaseException(ExceptionEnum.FAIL_CHECK);
        }
        //System.out.println(from);
        List<College> res = collegeService.findlist();
        return ResultUtil.TrueResult(res);
    }
}
